package com.psytech.app.task.tasks_mds.entity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.validator.NotNull;

/**
 * The persistent class for the task database table.
 */
@Entity
@Table(name = "task")
public class EntityTask implements Serializable, STMEntity {

	public static enum PRIORITY {
		HIGH, NORMAL, LOW
	}

	public static enum STATUS {
		PENDING, PROGRESS, COMPLETE
	}

	/**
	 * 
	 */
	private static final long serialVersionUID = 7918937518966327088L;

	@Id
	@NotNull
	private String uid;

	@Lob()
	private String description;

	@NotNull
	private String name;

	private String category;

	@NotNull
	@Enumerated(EnumType.STRING)
	private PRIORITY priority;

	private Date endDate;

	private Date startDate;

	private Date expectedEndDate;

	private Date expectedStartDate;

	@NotNull
	@Enumerated(EnumType.STRING)
	private STATUS status;

	@OneToMany(mappedBy = "task", targetEntity = EntityComment.class, cascade = CascadeType.REMOVE)
	private List<EntityComment> comments;

	@NotNull
	private String creatorUid;

	@OneToMany(mappedBy = "taskUid", targetEntity = EntityTodo.class, cascade = CascadeType.REMOVE)
	private List<EntityTodo> todo;

	/**
	 * Get the task Universal ID.
	 */
	public String getUid() {
		return uid;
	}

	/**
	 * A définir par la couche métier.
	 * 
	 * @param uid
	 *            Universal ID de la tâche.
	 */
	public void setUid(final String uid) {
		this.uid = uid;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(final String description) {
		this.description = description;
	}

	public String getName() {
		return name;
	}

	public void setName(final String name) {
		this.name = name;
	}

	public PRIORITY getPriority() {
		return priority;
	}

	public void setPriority(final PRIORITY priority) {
		this.priority = priority;
	}

	public Date getEndDate() {
		return endDate;
	}

	public void setEndDate(final Date endDate) {
		this.endDate = endDate;
	}

	public STATUS getStatus() {
		return status;
	}

	public void setStatus(final STATUS status) {
		this.status = status;
	}

	@Override
	public String toString() {
		return "Name => " + getName() + ", Uid => " + getUid();
	}

	public List<EntityComment> getComments() {
		if (comments == null)
			comments = new ArrayList<EntityComment>();
		return comments;
	}

	public void setComments(final List<EntityComment> comments) {
		this.comments = comments;
	}

	public String getCreatorUid() {
		return creatorUid;
	}

	public void setCreatorUid(final String creatorUid) {
		this.creatorUid = creatorUid;
	}

	public Date getStartDate() {
		return startDate;
	}

	public void setStartDate(final Date startDate) {
		this.startDate = startDate;
	}

	public Date getExpectedEndDate() {
		return expectedEndDate;
	}

	public void setExpectedEndDate(final Date expectedEndDate) {
		this.expectedEndDate = expectedEndDate;
	}

	public Date getExpectedStartDate() {
		return expectedStartDate;
	}

	public void setExpectedStartDate(final Date expectedStartDate) {
		this.expectedStartDate = expectedStartDate;
	}

	public void setCategory(final String category) {
		this.category = category;
	}

	public String getCategory() {
		return category;
	}

	public List<EntityTodo> getTodo() {
		if (todo == null)
			todo = new ArrayList<EntityTodo>();
		return todo;
	}

}